/**
 * ArquivoCatalogo
 * Descreve as informacoes do arquivo utilizadas no catalogo
 * Alison & Nuno - 08/06/10
 */
package catalogo;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ArquivoCatalogo implements java.io.Serializable
{
	/**
	 * 
	 */
	public static final int DIFERENT_NAMES = -1;
	public static final int ACTUALIZED_TIMESTAMP = 0;
	public static final int OLD_TIMESTAMP = 1;
	public static final int DELETED_FILE = 2;
	public static final int STATUS_IGNORED = 3;
	private static final long serialVersionUID = 9212449002151762571L;
	/*
	 * Fields
	 */
	private String nome;
	private Date data;
	private int timestamp;
	private String status;

	public ArquivoCatalogo() {
		super();
	}	

	public ArquivoCatalogo(String nome, Date data, int timestamp, String status) {
		super();
		this.nome = nome;
		this.data = data;
		this.timestamp = timestamp;
		this.status = status;
	}

	public ArquivoCatalogo(String nome, String data, int timestamp, String status) {
		super();
		this.nome = nome;
		DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
		try {
			this.data = df.parse(data);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		this.timestamp = timestamp;
		this.status = status;
	}	

	/*
	 * Getters and Setters
	 */
	public String getNome() {
		return nome;
	}
	public void setNome(String nome)
	{
		this.nome = nome;
	}
	public Date getData() {
		return data;
	}
	public void setData(Date data)
	{
		this.data = data;
	}
	public int getTimestamp()
	{
		return timestamp;
	}
	public void setTimestamp(int timestamp)
	{
		this.timestamp = timestamp;
	}
	public String getStatus()
	{
		return status;
	}
	public void setStatus(String status)
	{
		this.status = status;
	}

	public int diffArquivo(ArquivoCatalogo a)
	{
		if (!a.getNome().equals(this.nome))
			return DIFERENT_NAMES;
		else
		{
			if (a.getStatus().equals(Catalogo.STATUS_DELETED)&&this.status.equals(Catalogo.STATUS_OK)
					&& this.timestamp <= a.getTimestamp())
				return DELETED_FILE;
			else
			{
				if (this.timestamp>=a.getTimestamp())
					return ACTUALIZED_TIMESTAMP;
				else
				{
					if (a.getStatus().equals("OK")) 
						return OLD_TIMESTAMP;
					else
						return STATUS_IGNORED;
				}
			}
		}
	}
}
